#ifdef PBC_LAZY_COMPILE

// static
bool Compiler::LazyTransform(Isolate* isolate,
                             Handle<SharedFunctionInfo> shared_info,
                             Handle<Script> script,
                             IsCompiledScope* is_compiled_scope) {
#ifdef DEBUG
#ifdef V8_OS_OHOS
  v8::internal::StdoutStream{}
      << "[pbc] Lazy Transform in Compiler::LazyTransform "
      << (shared_info->function_literal_id()) << "\n";
#endif

  TRACE_EVENT0("v8," TRACE_DISABLED_BY_DEFAULT("v8.compile"),
                "V8.AOT.LazyTransform");
#endif
  if (v8_flags.log_pbc) {
    std::cout << "Lazy Transform in Compiler\n";
#ifdef OBJECT_PRINT
    std::cout << "sfi before lazy transform:\n";
    shared_info->SharedFunctionInfoPrint(std::cout);
#endif
  }
#if V8_MAJOR_VERSION == 11
  Handle<String> pbc_source(String::cast(script->pbc_source()), isolate);
#else
  Handle<String> pbc_source(Cast<String>(script->pbc_source()), isolate);
#endif
  base::Vector<const uint8_t> pbc_resource;

  {
    DisallowGarbageCollection no_gc;
    String::FlatContent content = pbc_source->GetFlatContent(no_gc);
    DCHECK(content.IsOneByte());
    pbc_resource = content.ToOneByteVector();
  }
  // 1. deserialize
  i::PbcDeserializer deserializer;
  const i::PbcScript* pbc_script =
      deserializer.Run(reinterpret_cast<const uint8_t*>(pbc_resource.data()),
                       static_cast<uint32_t>(pbc_resource.length()));

  // 2. transform
  i::LazyPbcTransformer transformer(*pbc_script, *isolate, script, shared_info);
  transformer.LazyRun();
  // shared_info->set_age(0);
  *is_compiled_scope = shared_info->is_compiled_scope(isolate);
  DCHECK(is_compiled_scope->is_compiled());
  return true;
}

#endif